#类和对象
class Animal
  def run()
    puts "#{@name} can run"
  end

  def swim()
    puts "#{@name} can swim"
  end

  def name(name)
    @name=name
  end

  def initialize(name = "Dog")
    @name=name
  end
end
cat=Animal.new("cat")
cat.run
puts '---------------------------------'
a=cat.methods
b=Animal.instance_methods false #上面那个没有这个参数

class Animal # 拆开类
  attr_accessor :name
end
puts cat.name, cat.run

#模块
module ToFile
  def filename
    "C:/Users/tzp/Projects/7-lan/ruby/object_#{self.object_id}.s"
  end

  def to_f
    File.open(filename, "w") { |f| f.write(to_s) }
  end
end
class Animal
  include ToFile
end
#puts cat.to_f